function PDPage(){
	
	this.bgColor=null;//閼冲本娅欐０婊嗗
	this.rotate=0;//妞ょ敻娼伴弮瀣祮鎼达拷
	this.operator=null;//閹垮秳缍旈崥宥忕礄New閿涘瓕elete閿涘odify閿涳拷
	//	this.pdfId=null;//pdf鐎电钖処D
	this.index = null;//妞ょ數鐖�
	this.associateDIV=null;//page鐎电懓绨查惃鍑濱V
	this.docId=null;//妞ょ敻娼伴幍锟界潣閻ㄥ嫭鏋冨顤廌
	this.pageId=null;
	this.pDPagesByHtml = null;
	this.m_PageMatrix = null;

	
	this.bFinishParseJson = false;
	this.bFinishLoadImgs = false;
	this.imgObjCount = 0;
	this.textObjCount = 0;
	this.textObjs = [];
	this.loadedImgObjCount = 0;
	
	this.callback = null;
	this.caller = null;

	this.pdDoc = null;
	this.width = 0;
	this.height = 0;
	
	this.pdPageObjects = null;
	this.pDAnnotListData = null;
	this.m_annotList = null;
	
	this.m_FormControlList = null;
}

PDPage.prototype.GetAnnotList = function () {
    return this.m_annotList;
};

PDPage.prototype.GetFormControlList = function () {
    return this.m_FormControlList;
};

PDPage.prototype.OnImgLoaded = function() {
	this.pdPage.loadedImgObjCount += 1;
	if (!this.pdPage.bFinishParseJson) {
		this.pdPage = null;
		return;
	}
	if (this.pdPage.loadedImgObjCount < this.pdPage.imgObjCount) {
		this.pdPage = null;
		return;
	}
	this.pdPage.bFinishLoadImgs = true;
	if (null != this.pdPage.callback && null != this.pdPage.caller) {
		this.pdPage.callback.call(this.pdPage.caller);
	}
	this.pdPage = null;
};


PDPage.prototype.SetPDDoc = function (doc) { this.pdDoc = doc; };
PDPage.prototype.GetPDDoc = function () { return this.pdDoc; };
PDPage.prototype.SetSize = function (w, h) { this.width = w; this.height = h; };
PDPage.prototype.GetSize = function () { return [this.width, this.height]; };
PDPage.prototype.GetDisplayMatrix = function (xPos, yPos, xSize, ySize, iRotate) { //xPos,yPos瀹革箒顫楁い鍓佸仯閿涘瘓Size,ySize妞ょ敻娼伴弰鍓с仛妤傛ê顔旈敍瀹≧otate:0-娑撳秵妫嗘潪锟�-妞ょ儤妞傞柦鍫熸鏉烇拷0鎼达拷2-180鎼达拷3-270鎼达拷
    if (this.width == 0 || this.height == 0)
        return null;
    //calculate matrix 
    var x0 = 0; var y0 = 0;
    var x1 = 0; var y1 = 0;
    var x2 = 0; var y2 = 0;
    iRotate %= 4;
    switch (iRotate) {
        case 0:
            // ll -> ll
            x0 = xPos; y0 = yPos + ySize;
            // ul -> ul
            x1 = xPos; y1 = yPos;
            // lr -> lr
            x2 = xPos + xSize; y2 = yPos + ySize;
            break;
        case 1:
            // ll -> ul
            x0 = xPos; y0 = yPos;
            // ul -> ur
            x1 = xPos + xSize; y1 = yPos;
            // lr -> ll
            x2 = xPos; y2 = yPos + ySize;
            break;
        case 2:
            // ll -> ur
            x0 = xPos + xSize; y0 = yPos;
            // ul -> lr
            x1 = xPos + xSize; y1 = yPos + ySize;
            // lr -> ul
            x2 = xPos; y2 = yPos;
            break;
        case 3:
            // ll -> lr
            x0 = xPos + xSize; y0 = yPos + ySize;
            // ul -> ll
            x1 = xPos; y1 = yPos + ySize;
            // lr -> ur
            x2 = xPos + xSize; y2 = yPos;
            break;
    }


    var mt = new PDMatrix();
    //then returned in a array
    mt.Set(((x2 - x0) / this.width), ((y2 - y0) / this.width), ((x1 - x0) / this.height), ((y1 - y0) / this.height), x0, y0);
    var m = new PDMatrix();
    m.Set(this.m_PageMatrix.a, this.m_PageMatrix.b, this.m_PageMatrix.c, this.m_PageMatrix.d, this.m_PageMatrix.e, this.m_PageMatrix.f);
    var finalMt = PDMatrix.prototype.Concat2mt(m, mt);
    return finalMt;
};
	PDPage.prototype.SetPDPagesByHtml=function(pDPagesByHtml){
		this.pDPagesByHtml=pDPagesByHtml;
	};
	PDPage.prototype.GetPDPagesByHtml=function(){
		return this.pDPagesByHtml;
	};
	PDPage.prototype.SetPageId=function(pageId){
		this.pageId=pageId;
	};
	PDPage.prototype.GetPageId=function(){
		return this.pageId;
	};
	PDPage.prototype.SetDocId=function(docId){
		this.docId=docId;
	};
	PDPage.prototype.GetDocId=function(){
		return this.docId;
	};
	
	PDPage.prototype.SetAssociateDIV=function(associateDIV){
		this.associateDIV=associateDIV;
	};
	PDPage.prototype.GetAssociateDIV=function(){
		return this.associateDIV;
	};
    
	PDPage.prototype.SetIndex=function(id){
		this.index=id;
	};
	PDPage.prototype.GetIndex=function(){
		return this.index;
	};
    
	PDPage.prototype.SetOperator=function(operator){
		this.operator=operator;
	};
	PDPage.prototype.GetOperator=function(){
		return this.operator;
	};
	PDPage.prototype.SetBgColor=function(bgColor){
		this.bgColor=bgColor;
	};
	PDPage.prototype.GetBgColor=function(){
		return this.bgColor;
	};
	PDPage.prototype.SetRotate=function(rotate){
		this.rotate=rotate;
	};
	PDPage.prototype.GetRotate=function(){
		return this.rotate;
	};



	PDPage.prototype.ParseJson = function (ArrayData) {
	    var page = this;

	    page.SetBgColor(ArrayData[0]);
	    page.SetRotate(ArrayData[1]);
	    var arrMt = ArrayData[2];
	    this.m_PageMatrix = new PDMatrix();
	    if (arrMt != null && arrMt.length == 6) {
	        this.m_PageMatrix.Set(arrMt[0], arrMt[1], arrMt[2], arrMt[3], arrMt[4], arrMt[5]);
	    }


	    //set the page size
	    var s = this.pdDoc.GetPageSize(this.index);
	    this.SetSize(s[0], s[1]);
	};

	PDPage.prototype.AddPageObjects = function (jsonData) {

	    this.pdPageObjects = new PDPageObjects();
	    this.pdPageObjects.ParseJson(jsonData);
	  
	    this.bFinishParseJson = true;
	};

	PDPage.prototype.ParseFromBin = function (rd) {
	    this.pdPageObjects = new PDPageObjects(this.pdDoc);
	    this.pdPageObjects.type = 0; // type  0:page  1:form
	    this.pdPageObjects.m_csImgPath = this.pdDoc.m_imgPath;
	    this.pdPageObjects.ParseFromBin(rd);
//	    var bHasAnnot = rd.readByte();
//	    if (bHasAnnot == 1) {
//	        this.m_annotList = new PDAnnotListData(this);
//	        this.m_annotList.setImgPath(this.pdDoc.m_imgPath);
//	        this.m_annotList.parseAnnotListData(rd);
//	    }
//		
//		var bHasFormControl = rd.readByte();
//		if (bHasFormControl == 1){
//			var nControlsCount = rd.readInt32();
//			this.m_FormControlList = [];
//			for (var i = 0; i < nControlsCount; ++ i){
//				var controlData = new PDFormControl(this);
//				controlData.parseFormControl(rd);
//				this.m_FormControlList[i] = controlData;
//			}
//		}
	    this.bFinishParseJson = true;
	};


	PDPage.prototype.GetPageObjects = function () {
	    return this.pdPageObjects;

	};

PDPage.prototype.GetMatrixByID = function(id) {
    return this.pdPageObjects.GetMatrixByID;
};

PDPage.prototype.AddGenState = function (id, jsonData) {
    var state = this.GetGenStateByID(id);
    if (null == state) {//娑撳秴鐡ㄩ崷顭掔礉閺傛澘缂�
        var s = new PDGeneralState();
        s.ParseJson(jsonData);
        this.pdPageObjects.genStates.push(s);
    } else {
        state.ParseJson(jsonData);
    }
};


PDPage.prototype.GetGenStateByID = function (id) {
for (var i = 0; i < this.pdPageObjects.genStates.length; i++) {
if (id == this.pdPageObjects.genStates[i].uID) { return this.pdPageObjects.genStates[i]; }
}
return null;
};
PDPage.prototype.CountGenState = function () { return this.pdPageObjects.genStates.length; };
PDPage.prototype.GetGenStateByIndex = function (index) {
if (index < 0 || index >= this.pdPageObjects.genStates.length) return null;
return this.pdPageObjects.genStates[index];
};


PDPage.prototype.AddGraphState = function (id, jsonData) {
	var state = this.GetGraphStateByID(id);
	if (null == state) {//娑撳秴鐡ㄩ崷顭掔礉閺傛澘缂�
		var s = new PDGraphState();
		s.ParseJson(jsonData);
		this.pdPageObjects.graphStates.push(s);
	} else {
		state.ParseJson(jsonData);
	}
};
PDPage.prototype.GetGraphStateByID = function (id) {
	var self = this;
	for (var i = 0; i < this.pdPageObjects.graphStates.length; i++) {
		if (id == this.pdPageObjects.graphStates[i].uID)
			return this.pdPageObjects.graphStates[i];
	}
	return null;
};
PDPage.prototype.CountGraphState = function () { return this.pdPageObjects.graphStates.length; };
PDPage.prototype.GetGraphStateByIndex = function (index) {
if (index < 0 || index >= this.pdPageObjects.graphStates.length) return null;
return this.pdPageObjects.graphStates[index];
};


PDPage.prototype.AddClrState = function (id, jsonData) {
var state = this.GetClrStateByID(id);
if (null == state) {//娑撳秴鐡ㄩ崷顭掔礉閺傛澘缂�
var s = new PDColorState();
s.ParseJson(jsonData);
this.pdPageObjects.clrStates.push(s);
} else {
state.ParseJson(jsonData);
}
};
PDPage.prototype.GetClrStateByID = function (id) {
for (var i = 0; i < this.pdPageObjects.clrStates.length; i++) {
if (id == this.pdPageObjects.clrStates[i].uID) return this.pdPageObjects.clrStates[i];
}
return null;
};
PDPage.prototype.CountClrState = function () { return this.pdPageObjects.clrStates.length; };
PDPage.prototype.GetClrStateByIndex = function (index) {
if (index < 0 || index >= this.pdPageObjects.clrStates.length) return null;
return this.pdPageObjects.clrStates[i];
};


PDPage.prototype.AddTextState = function (id, jsonData) {
var state = this.GetTextStateByID(id);
if (null == state) {//娑撳秴鐡ㄩ崷顭掔礉閺傛澘缂�
var s = new PDTextState();
s.ParseJson(jsonData);
this.pdPageObjects.textStates.push(s);
} else {
state.ParseJson(jsonData);
}
};
PDPage.prototype.GetTextStateByID = function (id) {
for (var i = 0; i < this.pdPageObjects.textStates.length; i++) {
if (id == this.pdPageObjects.textStates[i].uID) return this.pdPageObjects.textStates[i];
}
return null;
};
PDPage.prototype.CountTextState = function () { return this.pdPageObjects.textStates.length; };
PDPage.prototype.GetTextStateByIndex = function (index) {
if (index < 0 || index >= this.pdPageObjects.textStates.length) return null;
return this.pdPageObjects.textStates[i];
};

PDPage.prototype.AddClipPathState = function (id, jsonData) {
var state = this.GetClipPathStateByID(id);
if (null == state) {//娑撳秴鐡ㄩ崷顭掔礉閺傛澘缂�
var s = new PDClipPathState();
s.ParseJson(jsonData);
this.pdPageObjects.clpathStates.push(s); 
}else {
state.ParseJson(jsonData);
}
};
PDPage.prototype.GetClipPathStateByID = function (id) {
for (var i = 0; i < this.pdPageObjects.clpathStates.length; i++) {
if (id === this.pdPageObjects.clpathStates[i].uID) return this.pdPageObjects.clpathStates[i];
}
return null;
};
PDPage.prototype.CountClipPathState = function () {
return this.pdPageObjects.clpathStates.length;
};
PDPage.prototype.GetClipPathStateByIndex = function (index) {
if (index < 0 || index >= this.pdPageObjects.clpathStates.length) return null;
return this.pdPageObjects.clpathStates[i];
};


PDPage.prototype.GetPageObjByID = function(pageObjID) {
for (var i = 0, len = this.pdPageObjects.objectArr.length; i < len; i++) {
if (this.pdPageObjects.objectArr[i].objectID === pageObjID) {
return this.pdPageObjects.objectArr[i];
}
}
return null;
};
PDPage.prototype.GetPageObjByIndex = function(pageObjIndex) {
if (pageObjIndex >= this.pdPageObjects.objectArr.length || pageObjIndex < 0) return;
return this.pdPageObjects.objectArr[pageObjIndex];
};
PDPage.prototype.AddPageObj = function(pageObjID, objJsonData) {
var oldPageObj = this.GetPageObjByID(pageObjID);
if (null === oldPageObj) {
var pageObj = PageObj.prototype.FromJson(objJsonData);
this.pdPageObjects.objectArr.push(pageObj);
}
else {
oldPageObj.ParseJson(objJsonData);
}
};
PDPage.prototype.CountPageObj = function() {
return this.pdPageObjects.objectArr.length;
};
PDPage.prototype.InsertPageObj = function(index, objJsonData) {
	
};











